import request from "./request.js";
import {getRefreshToken} from "./token.js";

let promise
export const refreshToken = () => {
    if(promise) {
        return promise
    }
    promise = new Promise( async (resolve) => {
        console.log('刷新token')
        const resp = await request.get('/refresh_token', {
            headers: {
                Authorization: `Bearer ${getRefreshToken()}`
            },
            __isRefreshToken: true
        })
        resolve(resp.code === 0)
    })
    promise.finally(() => {
        promise = null
    })
    return promise

}


export const isRefreshToken = (config) => {
    return !!config.__isRefreshToken // 变量转换为 boolean 类型
}
